Frequency execution monitoring in a real-time embedded system

ABSTRACT

A method includes reading first and second timer count values from a timer. The first timer count value is associated with a first time point, and the second timer count value is associated with a second time point. Also, the method includes calculating a difference between the first and the second timer count values, and determining whether the difference is within a range. The range is based on a desired executing frequency to perform a computing task, a variation of the desired executing frequency, and a timer frequency. Further, based on the difference not being within the range, the method includes setting an error flag value to be true and incrementing an error count value.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.14/272,120 filed May 7, 2014, which claims priority to U.S. ProvisionalPatent Application Ser. No. 61/821,917 filed May 10, 2013, theentireties of both of which are incorporated herein by reference.

BACKGROUND

A real-time operating system is a computing environment that reacts toinput to perform a task within a specific time period. Each task to beperformed in the operating system may be executed at a predeterminedrate.

SUMMARY

Systems and methods to monitor an execution frequency of a task aredescribed herein. In an embodiment, a method includes reading first andsecond timer count values from a timer, wherein the first timer countvalue is associated with a first time point and the second timer countvalue is associated with a second time point, calculating a differencebetween the first and the second timer count values, and determiningwhether the difference is within a range, wherein the range is based ona desired executing frequency to perform a computing task, a variationof the desired executing frequency, and a timer frequency. Further,based on the difference not being within the range, the method includessetting an error flag value to be true and incrementing an error countvalue.

In another embodiment, a system includes a timer and a processingresource coupled to the timer. The timer is configured to generate aplurality of timer count values that are a time series of values with aperiod of an inverse value of a timer frequency. The processing resourceis configured to read first and second timer count values from thetimer, calculate a difference between the first and the second timercount values, and determine whether the difference is within a range,wherein the range is based on a desired executing frequency to perform,by the processor, a computing task, a variation of the desired executingfrequency, and the timer frequency. More particularly, based on thedifference not being within the range, the processing resource isfurther configured to set an error flag value to be true and incrementan error count.

In a further embodiment, a non-transitory, computer-readable storagedevice containing instructions that, when executed by a processingresource, cause the processing resource to read first and second timercount values from a timer, calculate a difference between the first andthe second timer count values, determine whether the difference iswithin a range, wherein the range is based on a desired executingfrequency to perform, by the processor, a computing task, a variation ofthe desired executing frequency, and the timer frequency. Based on thedetermined difference, if the difference is not within the range, theprocessing resource executes the instructions to cause the processingresource to set an error flag value to be true and increment an errorcount; on the other hand, if the difference is within the range, theprocessing resource executes the instructions to cause the processingresource to set the error flag value to be false.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 shows a system to monitor frequency execution in accordance withvarious embodiments.

FIG. 2 show an exemplary signal of a time-varying timer count value inaccordance with various embodiments.

FIG. 3 shows an example of a frequency execution monitoring module inaccordance with various embodiments.

FIG. 4 shows a method to monitor a frequency execution in accordancewith various embodiments.

DETAILED DESCRIPTION OF EXAMPLE EMBODIMENTS

In this description, the term “couple” or “couples” means either anindirect or direct connection. Thus, if a first device couples to asecond device, that connection may be through a direct connection, orthrough an indirect connection via other devices and connections.

An operating system is configured to manage hardware resources of acomputing device and host applications that run on the computing device.More specifically, a real-time operating system (RTOS) is an operatingsystem designated to perform tasks (e.g., host applications) with veryprecise timing and a high degree of reliability. Such characteristics ofthe RTOS may be advantageously implemented in measurement and automationsystems wherein, for example, downtime of the system is costly or asafety hazard may be caused due to a delay of executing a particulartask.

By “real-time”, it is meant that an operating system may include apredetermined maximum amount of time for each of tasks that theoperating system performs, or include a consistent level regarding theamount of time the operating system takes to accept and complete each ofthe tasks. As such, the RTOS is commonly used to perform multitasking.Multitasking is a method in which multiple tasks are performed duringthe same period of time. Generally, for a system implementing a RTOS formultitasking, the system may use certain algorithms or methods toschedule each task, such as preemptive priority and/or round robinscheduling. Regardless of which scheduling method is used, assuring atask is performed or executed at a predetermined rate, or at leastwithin an acceptable range of rates is beneficial to the successfulperformance of the system.

To assure a task is executed at a predetermined rate, describedembodiments provide systems and methods to monitor an executionfrequency of a task in an RTOS. Generally, the execution frequency is afrequency for a task to be executed, and the execution frequency may bedesignated by a user. More specifically, the execution frequency, orexecution time, may be referred to as time spent by a processor toperform the task. For example, a user may designate a particular task tobe executed by a processor every five second. Such designation of theexecution frequency may advantageously provide a precise timing toproduce correct results that the user originally desires. However,conventionally, the user who designates the execution frequency of atask is incapable of knowing whether the task is being executed at thedesired frequency.

Using the described systems and methods, a user may monitor theexecution frequency for each task and the user may be informed of anerror when a particular task is not executed within a predetermined oran acceptable range of execution frequency (i.e., rate). Once the erroris received by the user, the user may take further action in anysuitable purposes. For example, the user may tailor an instruction toexecute the particular task accordingly so as to cause the task to beexecuted at a desired rate. Thus, the described embodiments mayadvantageously provide a more efficient way to implement the RTOS with aprecise timing for scheduling each of the tasks among a multitaskingsystem, and in turn, enhance the performance of the system. Generally,the term “task” is a programmed instruction which is synonymous to a“thread”, or a “process”.

FIG. 1 shows a system 100 to monitor the execution frequency inaccordance with various embodiments. The system 100 includes a timer102, a non-transitory, computer-readable storage device 106, and aprocessing resource 104 coupled to the timer 102 and the non-transitory,computer-readable storage device 106. More particularly, thenon-transitory, computer-readable storage device 106 includes afrequency execution monitoring (FEM) module 108 which is executed by theprocessing resource 104.

In FIG. 1, the timer 102 is configured to measure elapsed time, forexample by counting timer count values provided to the processingresource 104. Preferably, the timer count values are a time series ofvalues with a period, and the processing resource 104 is configured toread the timer count values. By knowing a value of the period and anytwo timer count values at the beginning and end of executing a task,time spent by the processing resource 104 to finish the task may beprovided. Details of a relation between the spent time and the periodwill be explained with respect to the exemplary signal generated by thetimer 102 in FIG. 2. In general, the period is defined as an inversevalue of a timer frequency f_(t). In a preferred embodiment, if thetimer 102 is an incrementing timer, the timer 102 increments the timercount value for each transition of an input clock signal provided to thetimer 102. Analogously, if the timer 102 is a decrementing timer, thetimer 102 decrements the timer count value for each transition of theinput clock signal. Details of the timer count values will be describedwith respect to FIG. 2.

Still referring to FIG. 1, in accordance with various embodiments, theprocessing resource 104 may include one or more processors, wherein eachof the processors may include a single-core central processing unit(CPU) or a multi-core CPU. Additionally or alternatively, the computingresource 104 may be implemented as a computer or a computer cluster. Forease of illustration, the following discussion is based the computingresource 104 including a single-core CPU.

The system 100 preferably is a real-time embedded system. An embeddedsystem is an electronic system with a dedicated function within a largermechanical or electrical system, and the embedded system is commonlyembedded as part of a complete device often including hardware andmechanical components.

FIG. 2 shows an exemplary signal 201 of timer count values generated bythe timer 102 in accordance with various embodiments. As shown in FIG.2, the signal 201 includes a time series of values with a period,wherein the period is generally referred to as timer count intervalΔT_(t). The signal 201 shown in FIG. 2 is generated by a decrementingtimer, or a count-down timer. As such, the signal 201 typically startswith a starting timer count value (e.g., 203), and transitions to zeroas the timer count interval elapses. In other embodiments, the timer 102is an incrementing timer, and if a signal is generated by anincrementing timer, the signal may start at a zero value and count up toa final value when a timer count interval elapses. In a preferredembodiment, a timer frequency, f_(t), is defined as an inverse value ofthe timer count interval ΔT_(t).

Further, in accordance with a preferred embodiment, as described above,a task in a system implementing the multitasking is generally executedat a desired frequency which may be predetermined by a user. The desiredfrequency is generally referred as execution frequency, f_(e). Aninverse value of the desired execution frequency may be referred to asdesired execution time (T_(e)). Depending on the performance of thesystem such as how precise of the timing for each of the tasks to beexecuted, the desired execution time, T_(e), may be different from howmuch time, in practice, the processing resource spend finishing thetask. Conventionally, no systems or methods have been provided tomonitor the exact time spent by a processor to finish a task.

However, with these two frequencies (i.e., f_(t) and f_(e)), a methodmay be developed to monitor the execution frequency of a task executedby the system 100. In a preferred embodiment, a tolerable executionfrequency variation may be determined by the user to be, Δf_(e). Assuch, an allowable range of time for executing a task may be defined asequation (1),

$\begin{matrix}{\frac{1}{f_{e} + {\Delta f}_{e}} \leq {\Delta T} \leq {\frac{1}{f_{e} - {\Delta f}_{e}}.}} & (1)\end{matrix}$

More particularly, if an amount of time to execute the task does notreside within the allowable range, the execution may be regarded as anerror. Hereinafter, the amount of time to execute a task, ΔT, isreferred to as the execution time.

In a further embodiment, the equation (2) below may be derived fromequation (1) above for the purpose of decreasing a computational load ofthe processing resource 104. The equation (2) is shown as,

$\begin{matrix}{\frac{f_{t}}{f_{e} + {\Delta f}_{e}} \leq \frac{\Delta T}{{\Delta T}_{t}} \leq \frac{f_{t}}{f_{e} - {\Delta f}_{e}}} & (2)\end{matrix}$

where ΔT_(t) is the timer count interval, and f_(t) is the inverse valueof the timer count interval, that is, the timer frequency.

Still in a preferred embodiment, the execution time can be measured bythe timer 102, so that the execution time ΔT may be expressed for adecrementing timer as equation (3) shown below,

ΔT=(cnt_(n)−cnt_(n+1))·ΔT _(t)  (3)

where cnt_(n) is the timer count value (e.g., 203) for the n^(th)iteration of the task being executed, and analogously, cnt_(n+1) is thetimer count value for the (n+1)^(th) iteration of the task beingexecuted. Typically, the n^(th) iteration is associated with a firstvalue of time and the (n+1)^(th) iteration is associated with a secondvalue of time successively to the first value of time. If the timer 102is a decrementing timer, the difference between cnt_(n) and cnt_(n+1)(i.e., cnt_(n)−cnt_(n+1)) is positive; in order to maintain thedifference to be a positive value, the difference may be expressed as,cnt_(n+1)−cnt_(n), for an incrementing timer. Replacing the term

$\frac{\Delta T}{{\Delta T}_{t}}$

in equation (2) may result in a new equation for the allowable executiontime, which is shown as equation (4),

$\begin{matrix}{\frac{f_{t}}{f_{e} + {\Delta f}_{e}} \leq \left( {{cnt}_{n} - {cnt}_{n + 1}} \right) \leq \frac{f_{t}}{f_{e} - {\Delta f}_{e}}} & (4)\end{matrix}$

In a further embodiment, the lower bound of the equation (4) may besimplified as Δcnt_(min), wherein Δcnt_(min) may be referred to as aminimum allowable counter difference. Similarly, the upper bound mayalso be simplified as Δcnt_(max), wherein Δcnt_(max) may be referred toas a maximum allowable counter difference. Thus, the equation issimplified as

Δcnt_(min)≤Δcnt≤Δcnt_(max),  (5).

By using equation (5), whether a task is executed at a rate (frequency)within an allowable range can be determined. More particularly, sincethe lower bound and the higher bound in the equation (5) are based onparameters (f_(t), f_(e), and Δf_(e)) predetermined by the user, readingtwo successive timer count values from the timer 102 may cause theprocessing resource 104 to determine whether the task is executed at anallowable frequency.

Also, in some embodiments, the processing resource 104 may be capable ofdetecting a transition (e.g., 207) while reading the timer count valuefrom the timer 102. The transition (e.g., 207) occurs when a first timercount interval elapses and a successive second timer count initiates.Once the transition is detected by the processing resource 104, theprocessing resource 104 may add the starting value (e.g., 203) to theexecution time difference (i.e., Δcnt) to avoid causing a singularitywhile implementing the described method to monitor the executionfrequency.

FIG. 3 shows a block diagram to further illustrate the non-transitory,computer-readable storage device 106 in accordance with variousembodiments. The storage device 106 includes a variety of modules thatcan be executed by the processing resource 104 to perform any or all ofthe functionality described herein.

As shown in the example of FIG. 3, the FEM module 108 includes threemodules which may include a timer count value read module 302, adifference of timer count value calculation module 304, and a differenceof timer count value determination module 306. Each module of FIG. 3 isexecuted by the processing resource 104 to implement the functionalitydescribed herein. The functions to be implemented by executing themodules 302, 304, and 306 will be described with reference to the flowdiagram of FIG. 4. The combination of the computing resource 104executing a particular module represents an “engine.” Thus, theprocessing resource executing the various modules implements a timercount value read engine, a difference of timer count value calculationengine, and a difference of timer count value determination engine.

FIG. 4 shows a flow diagram 400 to explain the implementation of thefrequency execution monitoring (FEM) module 108 in accordance withvarious embodiments. The flow diagram starts with block 402, byexecuting the timer count value read module 302, to read a first and asecond timer count values, wherein the first timer count value isassociated with a first iteration of the task being executed and thesecond timer count value is associated with a second iteration. In apreferred embodiment, the second iteration is successive in time to thefirst iteration.

As a result of executing the difference of timer count value calculationmodule 304, the flow diagram 400 routes to block 404 to calculate adifference (i.e., Δcnt) between the first and the second timer countvalues. In a preferred embodiment, if the timer 102 is a decrementingtimer, the difference is calculated as the first timer count value minusthe second timer count value. Once the difference has been calculated atblock 404, the flow diagram may route to block 406. At block 406, thedifference of timer count value determination module 306 is executed todetermine whether the difference is within the allowable range ofexecution time, based on the equation (5).

Still referring to the flow diagram 400, if the difference is within therange, the flow diagram 400 routes to block 408 to set an error flagvalue to be false. However, if the difference is not within the range,the flow diagram 400 routes to block 410 to set the error flag value tobe true.

Modifications are possible in the described embodiments, and otherembodiments are possible, within the scope of the claims.

What is claimed is:
 1. A method comprising: reading, by a processingresource, from a timer, a first count value associated with a firstexecution of a task of a real time operating system and a second countvalue associated with a second execution of the task; calculating a testvalue based on a difference between the first count value and the secondcount value; determining whether the test value is in a predeterminedrange of values; and setting an error flag to be true if the test valueis not within the predetermined range or setting the error flag to befalse if the test value is within the predetermined range.
 2. The methodof claim 1, wherein the timer comprises a decrementing counter having afinite number of values and wherein when the timer reaches a minimumvalue, the timer transitions to a maximum counting value of the timerand, when the timer transitions to the maximum counting value at a pointin time between the reading of the first and second count values, themethod includes: basing the calculation of the test value additionallyon an addition of the maximum count value of the timer to the differencebetween the first count value and the second count value.
 3. A systemcomprising: a timer to generate count pulses of a clock signal and togenerate output count values; and a processing resource coupled to thetimer and to a storage device containing executable instructions that,when executed by the processing resource, cause the processing resourceto: read, from the timer, a first count value associated with a firstexecution of a task of a real time operating system and a second countvalue associated with a second execution of the task; calculate a testvalue based on a difference between the first count value and the secondcount value; determine whether the test value is in a predeterminedrange; and set an error flag to be true if the test value is not withinthe range or set the error flag to be false if the test value is withinthe range.
 4. The system of claim 3, wherein the processing resource isat least one of: (a) a single core central processing unit (CPU), (b) amulti-core CPU, or (c) a computer cluster.
 5. The system of claim 3, thetimer comprises a decrementing counter having a finite number of valuesand wherein when the timer reaches a minimum value, the timertransitions to a maximum counting value of the timer and whereinresponsive to the timer transitioning to the maximum count value at apoint in time between the reading of the first and second count values,the processing resource is caused to base the calculation of the testvalue additionally on an addition of the maximum count value of thetimer to the difference between the first count value and the secondcount value.
 6. The method of claim 1, further comprising: reading, bythe processing resource, from the timer, a first count value associatedwith a first execution of a second task of the real time operatingsystem and a second count value associated with a second execution ofthe second task; calculating a second test value based on a differencebetween the first count value of the second task and the second countvalue of the second task; determining whether the second test value isin a second predetermined range of values; and setting a second errorflag to be true if the second test value is not within the secondpredetermined range or setting the error flag to be false if the testvalue is within the second predetermined range.
 7. The system of claim3, wherein the executable instructions, when executed by the processingresource, further cause the processing resource to: read, from thetimer, a first count value associated with a first execution of a secondtask of the real time operating system and a second count valueassociated with a second execution of the second task; calculate asecond test value based on a difference between the first count value ofthe second task and the second count value of the second task;determining whether the second test value is in a second predeterminedrange of values; and setting a second error flag to be true if thesecond test value is not within the second predetermined range orsetting the error flag to be false if the test value is within thesecond predetermined range.